package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDao customerDao;
    @Override
    public List<Customer> getPage(Integer page, Integer rows, String customerName) {
        int start = (page - 1) * rows;
        List<Customer> list = customerDao.getPage(start,rows,customerName);
        return list;
    }

    @Override
    public void update( Customer customer) {
        if(customer.getCustomerId()!=null){
            customerDao.update(customer);
        }else{
            customerDao.insert(customer);
        }
    }

    @Override
    public void delete(String ids) {
        if(null != ids && ids != ""){
            String[] split = ids.split(",");
            for (String id : split) {
                if(null != id && id != ""){
                    customerDao.delete(Integer.parseInt(id));
                }
            }
        }
    }

    @Override
    public List<Customer> selectByName(String q) {
        return customerDao.selectByName(q);
    }
}
